﻿ <?php
/**********************************************************
** Lime Manager
** Thomas Knobloch & Clément Troesch
** Manager Ajax Tables View
***********************************************************/
?>
<?php include_once "../../model/DevelopperModel.php"; ?>
<?php include_once "../../model/SessionModel.php"; ?>
<?php include_once "../../model/DevelopperModel.php"; ?>
<?php session_start(); ?>

<div class="section_title" id="tables"><h1> Sauvegarde </h1></div>
<div class="section_info">
	Générer et démarrer le script de sauvegarde à chaud de ses objets.
</div>

<div class="article">

<div class="section_title_small_blue"><h4>Sélectionnez un fichier</h4></div>

	<?php
	if($_SESSION['session']->currentConnection->type == "ORACLE")
	{
	// ORACLE
	?>
	
	La sauvegarde se fera dans le dossier que vous aurez séléctionné:<br />
	Dossier: <input id="path" type="text" size="40" value="<?php echo isset($_GET['selected_path'])?$_GET['selected_path']:"" ?>" />
	<br /><br />
	<input type="button" value="Générer le script" onClick="displaySave($('#path').val())" />
	
	<?php
	}
	else if($_SESSION['session']->currentConnection->type == "MYSQL")
	{
	//MYSQL
	$dumpExe = "C:\wamp\bin\mysql\mysql5.5.24\bin\\";
	if(isset($_GET['selected_dumpexe']))
	{
		$dumpExe = $_GET['selected_dumpexe'];
	}
	

	
	
	?>
	
	Séléctionnez l'emplacement de l'executable "mysqldump" sur votre système:<br />
	<input id="dumpExe" type="text" value="<?php echo $dumpExe ?>" size="40" /><br /><br />
	
	La sauvegarde se fera dans le fichier que vous aurez séléctionné:<br />
	Fichier: <input id="path" type="text" size="40" value="<?php echo isset($_GET['selected_path'])?$_GET['selected_path']:"" ?>" />
	<br /><br />
	<input type="button" value="Générer le script" onClick="displaySave($('#path').val(), $('#dumpExe').val())" />
	
	
	<?php
	}
	?>
	
	
	
	<br /><br />
	
<?php
	
	if(isset($_GET['selected_path']))
		$path = $_GET['selected_path'];
		
	if(isset($path))
	{
		if($_SESSION['session']->currentConnection->type == "ORACLE")
			$script = DevelopperModel::getOracleHotSave($_SESSION['session']->currentConnection, $path);
		else if($_SESSION['session']->currentConnection->type == "MYSQL")
			$script = DevelopperModel::getMySQLHotSave($_SESSION['session']->currentConnection, $path, $dumpExe);
?>
	
	<div class="sql_code">
	<pre class="sh_sql">
		<?php
		echo "\n";
		echo $script;
		?>
	</pre>
	</div>
	
	<br /><br />
	<?php
	if($_SESSION['session']->currentConnection->type == "MYSQL")
	{
		echo "Note: Remplacez le mot \"[PASS]\" par votre mot de passe.";
		
	}
	?>
	<br />
	
	<?php
		if($_SESSION['session']->currentConnection->type == "ORACLE")
		{
			?><a href="view/main/DownloadView.php?name=Save.sql&text=<?php echo urlencode($script) ?>" target="_blank"><input type="button" value="Télécharger" /></a><?php
		}
		else if($_SESSION['session']->currentConnection->type == "MYSQL")
		{
			?><a href="view/main/DownloadView.php?name=Save.bat&text=<?php echo urlencode($script) ?>" target="_blank"><input type="button" value="Télécharger" /></a><?php
		}
			
	?>
	
	
<?php
	}
	
?>
	
	
	
	
	
	
	
	
	
	
	
	
</div>

<script type="text/javascript" src="js/sql/shjs.js"></script>
<script type="text/javascript" src="js/sql/sh_sql.js"></script>
<script type="text/javascript">

	//JQuery main entry point
	 $(document).ready(function() {
		//Highlight query
		sh_highlightDocument();
	 });
</script>


